# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=taglib

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.9.1
pkgrel=2
pkgdesc="A Library for reading and editing the meta-data of several popular audio formats (mingw-w64)"
arch=('any')
url="http://taglib.github.com"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-cppunit")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=(http://taglib.github.io/releases/${_realname}-${pkgver}.tar.gz
    fix-finding-cppunit.patch
    fix-redefinition-NOMINMAX.patch)
md5sums=('0d35df96822bbd564c5504cb3c2e4d86'
         '35acd6a8db64597d01eff718a4279e41'
         '55421ca09d4f9d8bc426362d529b95aa')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/fix-finding-cppunit.patch
  patch -p1 -i ${srcdir}/fix-redefinition-NOMINMAX.patch
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  mkdir -p ${pkgdir}${MINGW_PREFIX}
  pushd ${pkgdir}${MINGW_PREFIX} > /dev/null
  export PREFIX_WIN=`pwd -W`
  popd > /dev/null

  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${PREFIX_WIN} \
    -DENABLE_STATIC:BOOL=OFF \
    -DWITH_ASF:BOOL=ON \
    -DWITH_MP4:BOOL=ON \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
